package xj.graph2d;

import java.awt.Font;

public class FontAttr implements java.io.Serializable {

  public String fontName;

  public int fontSize;

  public int fontStyle;

  public FontAttr(String name, int style, int size) {
    fontName = name;
    fontStyle = style;
    fontSize = size;
  }

  @Override
  public int hashCode() {
    return ((fontName.hashCode() << 8) + (fontSize << 2) + fontStyle);
  }

  @Override
  public boolean equals(Object obj) {
    if (obj != null && obj instanceof FontAttr) {
      FontAttr fa = (FontAttr) obj;
      return (fontName.equals(fa.fontName) && 
	      fontSize == fa.fontSize && 
	      fontStyle == fa.fontStyle);
    } else {
      return false;
    }
  }

  public String getFontName() {
    return fontName;
  }

  public int getFontSize() {
    return fontSize;
  }

  public int getFontStyle() {
    return fontStyle;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder(fontName);
    sb.append(' ').append(fontSize).append("pt");
    switch (fontStyle) {
    case Font.BOLD:
      sb.append(" Bold");
      break;
    case Font.ITALIC:
      sb.append(" Italic");
      break;
    case Font.BOLD | Font.ITALIC:
      sb.append(" Bold Italic");
      break;
    default:
    }
    return sb.toString();
  }

}
